//
// State
//
// An instance of this class should represent the 
// entire game state (static and dynamic).
// - 
//
State = function() {
    this.entities = [];
};
State.prototype.add = function(entity) {
    return this.entities.push(entity);
};

State.prototype.remove = function(entity) {
    var i = this.entities.indexOf(entity);
    if (i > -1)
        return this.entities.splice(i, 1)[0];

    console.warn('ent not in state');
    return null;
};

State.prototype.getEntityById = function(id) {
    var i, n, ents = this.entities;
    for (i = 0, n = this.entities.length; i < n; ++i)
        if (ents[i].id === id)
            return ents[i];
        
    return null;
};

State.prototype.empty = function() {
    this.entities = [];
};

State.prototype.serialize = function() {
    var ent, e, n, arr = [];
    
    for (e = 0, n = this.entities.length; e < n; ++e) {
        ent = this.entities[e];
        if (ent.isSolid)
            continue;
        arr.push({
            id: ent.id,
            po: ent.phyObj,
            cv: ent.centerVec,
            fv: ent.forwardVec,
            uv: ent.upVec,
            rv: ent.rightVec
        });
    }
    return arr;
};


